﻿using B.S.BasicData.Api.Read.Applications.Command;
using B.S.BasicData.Domains;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructures;
using MediatR;

namespace B.S.BasicData.Api.Read.Applications.CommandHandler
{
    public class PermissonDetailCommandHandler : IRequestHandler<PermissonDetailCommand, ApiResult<Permissons>>
    {
        private readonly IBaseRepository<Permissons> baseRepository;

        public PermissonDetailCommandHandler(IBaseRepository<Permissons> baseRepository)
        {
            this.baseRepository = baseRepository;
        }

        public Task<ApiResult<Permissons>> Handle(PermissonDetailCommand request, CancellationToken cancellationToken)
        {
            ApiResult<Permissons> result = new ApiResult<Permissons>();
            result.Code = ApiEnum.Success;
            result.Message = "列表明细展示成功";
            var list = baseRepository.GetAll().Where(x=>x.PermissonId==request.PermissonId);

            result.data = list.FirstOrDefault();
            return Task.FromResult(result);
        }
    }
}
